/**
 * Title: TokenController.java
 * Description: Copyright: Copyright (c) 2019 Company: BHFAE
 *
 * @author Sharp
 * @date 2019-7-28 22:58
 * @description Project Name: Tanya
 * @Package: com.srct.service.controller
 */
package com.sharp.authorization.controller.common;

import com.sharp.authorization.service.token.TokenService;
import com.sharp.kernel.config.response.Response;
import com.sharp.kernel.config.response.ResponseHandler;
import com.sharp.framework.vo.token.TokenVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Api(value = "TOKEN操作", tags = "COMMON-token操作")
@RestController("TokenController")
@RequestMapping(value = "")
public class TokenController {

    @Resource
    private TokenService tokenService;

    @ApiOperation(value = "获取token", notes = "获取token,确保服务正常")
    @RequestMapping(value = "/token", method = RequestMethod.GET)
    public ResponseEntity<Response<TokenVO>> fetchToken() {
        TokenVO res = TokenVO.builder().token(tokenService.fetchToken()).build();
        return ResponseHandler.generateResponse(res);
    }

    @ApiOperation(value = "检查token是否有效", notes = "检查token是否有效")
    @RequestMapping(value = "/token", method = RequestMethod.POST)
    public ResponseEntity<Response<Boolean>> verifyToken(String token, String userId) {
        return ResponseHandler.generateResponse(tokenService.verifyToken(token, userId));
    }
}
